<template>
  <nly-content-wrapper class="a-base-container">
    <div class="wh100 resize-table-container" style="padding:10px;">
      <div class="a-button-bar">
        <!-- <div style="margin-right:15px">
          <span>会计年度：</span>
          <a-month-picker v-model="date" placeholder="选择年度" />
        </div>-->
        <!-- <span style="margin-right:15px">本位币：人民币</span> -->
        <a-button type="primary" @click="enabled">启用</a-button>
        <a-button type="danger" @click="unabled">禁用</a-button>
      </div>
      <a-table
        rowKey="moduleCode" 
        class="a-base-table"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,getCheckboxProps}"
        :columns="columns"
        :pagination="false"
        :data-source="dataSource"
        :scroll="scroll"
        :loading="loading"
        @change="onTableChange"
        bordered
      ></a-table>
    </div>
  </nly-content-wrapper>
</template>
<script>
import { list as ListAccountModule, save as SaveAccountModule} from "@/api/erp/accountModule";

export default {
  data() {
    const columns = [
        {
          title: "系统编码",
          width: 140,
          dataIndex: "moduleCode",
          key: "moduleCode"
        },
        { 
          title: "系统名称",
          width: 140,
          dataIndex: "moduleName",
          key: "moduleName" 
        },
        {
          title: "启用会计年份",
          width: 140,
          dataIndex: "enableAccountYear",
          key: "enableAccountYear"
        },
        {
          title: "启用会计期间",
          width: 140,
          dataIndex: "enableAccountMonth",
          key: "enableAccountMonth"
        },
        {
          title: "启用自然日期",
          width: 140,
          dataIndex: "enableDate",
          key: "enableDate"
        },
        {
          title: "状态",
          width: 140,
          dataIndex: "status",
          key: "status",
          customRender: (text,record) => {
            return <a-tag color={text == null ? "gray" : text == 1 ? 'green' : 'red'}>{text == null ? "未启用" :text == 1 ? '启用' : '禁用'}</a-tag>
          }
        },
        {
          title: "启用人",
          width: 140,
          dataIndex: "realName",
          key: "realName"
        }
      ];
    return {
      dataSource:[
       
      ],
      columns,
      selectedRowKeys: [],//table选中keys
      selectedRows: [],//table选中records
    //表格滚动条
      scroll: { y: 500, x: 500 },
    };
  },
  mounted(){
      this.list();
  },
  methods: {
    //获取 账套 模块
    list(){
        ListAccountModule()
        .then(response => {
          if (response.code === 200) {
            const { data } = response;
            this.dataSource = data;
          }
        })
        .catch(error => {});
    },
    //批量 保存
    batchSave(postData){
      SaveAccountModule(postData)
      .then(response => {
          if (response.code === 200) {
            this.selectedRowKeys = [];
            this.selectedRows = [];
            //刷新数据
            this.list();
            this.$message.success("保存成功");
          }
        })
        .catch(error => {});
    },
    //选择表格项
    onSelectChange(selectedRowKeys, selectedRows) {
      console.log(selectedRowKeys,selectedRows);
      this.selectedRowKeys = selectedRowKeys;
      this.selectedRows = selectedRows;
    },
    //选择框的默认属性配置
    getCheckboxProps(record) {
      return {
        props: {
            disabled: record.isLocked , // Column configuration not to be checked
            // name: record.name,
            // indeterminate: disableKeys.includes(record.key)
        }
      }
    },
    //启用
    enabled() {
      if (this.selectedRows.length == 0) {
        this.$message.warning("至少选择一条数据");
      }
      const { selectedRows } = this;
      let postData = selectedRows.map(f=>{
          return {
            id: f.id,
            orgModuleId: f.orgModuleId,
            status:1
          }
      });
      this.batchSave(postData);
      console.log("启用功能数据",postData,selectedRows);
    },
    //禁用
    unabled() {
      if (this.selectedRows.length == 0) {
        this.$message.warning("至少选择一条数据");
      }
        const { selectedRows } = this;
      let postData = selectedRows.map(f=>{
          return {
            id: f.id,
            orgModuleId: f.orgModuleId,
            status: 0
          }
      });
      this.batchSave(postData);
      console.log("禁用功能数据",postData,selectedRows);
    }
  }
};
</script>
 
